import json
from bottle import request,response,route, run, template,static_file, time

#@route('/hello/:name')
#def index(name='World'):
#    return template('<b>Hello {{name}}</b>!', name=name)
@route('/')
@route('/index.html')
def indexFile():
	return static_file('index.html', root='../')

@route('/js/:fileName')
def staticJsFile(fileName):
	return static_file(fileName, root='../js/')

@route('/css/:fileName')
def staticCssFile(fileName):
	return static_file(fileName, root='../css/')

@route('/img/:fileName')
def staticImg(fileName):
	return static_file(fileName, root='../img/')

@route('/data/:fileName')
def staticData(fileName):
	return static_file(fileName, root='../data/')

@route('/hello/:name')
def index(name='World'):
	json_response="{\"success\" : \'true\' }"
	callback_function = request.GET.get('callback')
    	if callback_function:
    		json_response = ''.join([callback_function, '(', json_response, ')'])
    		print json_response
    	return json_response


@route('/agenda/')
def recipes_list():
    return { "success" : False, "paths" : [], "error" : "list not implemented yet" }

@route('/agenda/<name>', method='GET')
def agenda_show( name="Mystery Recipe" ):
    #return { "success" : False, "path" : "/PTH/TO/XML/"+name+".xml", "error" : "show not implemented yet" }
    json_data=open('agenda.json')
    print json_data
    #return json.dumps(d)
    return json_data

@route('/agenda/<name>', method='DELETE' )
def agenda_delete( name="Mystery Recipe" ):
    return { "success" : False, "error" : "delete not implemented yet" }

@route('/agenda/<name>', method='PUT')
def agenda_put( name="Mystery Recipe" ):
    return { "success" : False, "path" : "/PTH/TO/XML/"+name+".xml", "error" : "save not implemented yet" }

@route('/feedback/', method='PUT')
def feedback_put( name="Mystery Recipe" ):
    return { "success" : False, "path" : "/PTH/TO/XML/"+name+".xml", "error" : "save not implemented yet" }

@route('/feedbackOptions', method='POST')
def feedback_post_options( name="Mystery Recipe" ):
    print "content_type: "+request.content_type;
    json_data=request.json
    print json.dumps(json_data)
    return { "success" : False, "path" : "/PTH/TO/XML/"+name+".xml", "error" : "save not implemented yet" }

@route('/feedbackComment', method='POST')
def feedback_post_comment( name="Mystery Recipe" ):
    print "content_type: "+request.content_type;
    json_data=request.json
    print json.dumps(json_data)
    return { "success" : False, "path" : "/PTH/TO/XML/"+name+".xml", "error" : "save not implemented yet" }



run(host='localhost', port=8080, debug=True)


